package com.isoft.dailymanprovidor.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.isoft.dailymanprovidor.bean.ResponseData;
import com.isoft.dailymanprovidor.bean.ResultCode;
import com.isoft.dailymanprovidor.dao.MeetingMinutesDao;
import com.isoft.dailymanprovidor.entity.MeetingMinutes;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class MeetingMinutesService {
    @Autowired
    MeetingMinutesDao meetingMinutesDao;
    //分页获取会议纪要全部信息
    public ResponseData getall(Integer currentPage, Integer size){
        ResponseData responseData = new ResponseData();
        Page<MeetingMinutes> meetingMinutesPage=new Page<>();
        // 初始化分页参数
        if (currentPage == null){
            currentPage = 1;
        }
        if (size == null){
            size =10;
        }
        //构造查询条件
        meetingMinutesPage.setCurrent(currentPage).setSize(size);
        QueryWrapper<MeetingMinutes> wrapper=new QueryWrapper<>();

        //构造返回Controller 的结果
        responseData.setErrorCode(ResultCode.SUCCESS.getCode());
        responseData.setMsg(ResultCode.SUCCESS.getMessage());
        responseData.setData(meetingMinutesDao.selectPage(meetingMinutesPage,wrapper));
        return responseData;
    }
    //分页获取会议室预约信息
    public ResponseData getallmeetingmintues(Integer currentPage, Integer size,String meetingtitle,String meetingtime,String status){
        ResponseData responseData = new ResponseData();
        Page<MeetingMinutes> meetingMinutesPage=new Page<>();
        String time="2010-09-30 16:00:00";
        // 初始化分页参数
        if (currentPage == null){
            currentPage = 1;
        }
        if (size == null){
            size =10;
        }
        //构造查询条件
        meetingMinutesPage.setCurrent(currentPage).setSize(size);
        QueryWrapper<MeetingMinutes> wrapper=new QueryWrapper<>();
        wrapper.like("meetingtitle",meetingtitle);
        if(!status.equals("全部")) {
            wrapper.eq("status", status);
        }
        if(meetingtime==null||meetingtime.isEmpty()) {
            wrapper.gt("meetingtime",time);
        }else {
            wrapper.eq("meetingtime",meetingtime);
        }
        //构造返回Controller 的结果
        responseData.setErrorCode(ResultCode.SUCCESS.getCode());
        responseData.setMsg(ResultCode.SUCCESS.getMessage());
        responseData.setData(meetingMinutesDao.selectPage(meetingMinutesPage,wrapper));
        return responseData;
    }
    //查询会议纪要是否记录过
    public boolean existmeetingtitle(MeetingMinutes meetingMinutes){
        QueryWrapper wrapper=new QueryWrapper<>();
        wrapper.eq("number",meetingMinutes.getNumber());
        MeetingMinutes exist=meetingMinutesDao.selectOne(wrapper);
        if (exist!=null){
            return  true;
        }
        return false;
    }
    //新增会议纪要
    public boolean addmeetingmintues(MeetingMinutes meetingMinutes){
        return  meetingMinutesDao.addmeetingmintues(meetingMinutes)>0;
    }
    //状态改为归档（1）
    public boolean updatestatus(MeetingMinutes meetingMinutes){
        UpdateWrapper<MeetingMinutes> wrapper=new UpdateWrapper<>();
        wrapper.eq("id",meetingMinutes.getId());
        wrapper.set("status","1");
        return meetingMinutesDao.update(wrapper)>0;
    }
    //修改会议纪要
    public boolean updatemeeting(MeetingMinutes meetingMinutes){
        UpdateWrapper<MeetingMinutes> wrapper=new UpdateWrapper<>();
        wrapper.set("number",meetingMinutes.getNumber());
        wrapper.set("meetingtitle",meetingMinutes.getMeetingtitle());
        wrapper.set("host",meetingMinutes.getHost());
        wrapper.set("content",meetingMinutes.getContent());
        wrapper.set("meetingtime",meetingMinutes.getMeetingtime());
        wrapper.set("recordtime",meetingMinutes.getRecordtime());
        wrapper.set("recorder",meetingMinutes.getRecorder());
        wrapper.set("audiorecording",meetingMinutes.getAudiorecording());
        wrapper.eq("id",meetingMinutes.getId());
        return meetingMinutesDao.update(wrapper)>0;

    }

}
